local guanjue = fk.CreateSkill {

  name = "joyex__guanjue",

  tags = { Skill.Compulsory, },

}



guanjue:addEffect(fk.CardUsing, {
  name = "joyex__guanjue",
  anim_type = "offensive",
  frequency = Skill.Compulsory,
  events = {fk.CardUsing, fk.CardResponding},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(guanjue.name) and data.card.suit ~= Card.NoSuit and
      (player:getNextAlive():getMark("@joyex__guanjue-turn") == 0 or
      not table.contains(player:getNextAlive():getMark("@joyex__guanjue-turn"), data.card:getSuitString(true)))
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local mark = player:getNextAlive():getMark("@joyex__guanjue-turn")
    if mark == 0 then mark = {} end
    table.insert(mark, data.card:getSuitString(true))
    for _, p in ipairs(room:getOtherPlayers(player)) do
      room:doIndicate(player.id, {p.id})
      room:setPlayerMark(p, "@joyex__guanjue-turn", mark)
    end
  end,
})
guanjue:addEffect(fk.CardResponding, {
  name = "joyex__guanjue",
  anim_type = "offensive",
  frequency = Skill.Compulsory,
  events = {fk.CardUsing, fk.CardResponding},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(guanjue.name) and data.card.suit ~= Card.NoSuit and
      (player:getNextAlive():getMark("@joyex__guanjue-turn") == 0 or
      not table.contains(player:getNextAlive():getMark("@joyex__guanjue-turn"), data.card:getSuitString(true)))
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local mark = player:getNextAlive():getMark("@joyex__guanjue-turn")
    if mark == 0 then mark = {} end
    table.insert(mark, data.card:getSuitString(true))
    for _, p in ipairs(room:getOtherPlayers(player)) do
      room:doIndicate(player.id, {p.id})
      room:setPlayerMark(p, "@joyex__guanjue-turn", mark)
    end
  end,
})

guanjue:addEffect("prohibit", {
  name = "#joyex__guanjue_prohibit",
  prohibit_use = function(self, player, card)
    return player:getMark("@joyex__guanjue-turn") ~= 0 and table.contains(player:getMark("@joyex__guanjue-turn"), card:getSuitString(true))
  end,
  prohibit_response = function(self, player, card)
    return player:getMark("@joyex__guanjue-turn") ~= 0 and table.contains(player:getMark("@joyex__guanjue-turn"), card:getSuitString(true))
  end,
})

return guanjue